using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Gko.Utils
{
	/// <summary>
	/// Extensions for ICollection of T interaface
	/// </summary>
	public static class CollectionExtensions
	{
		/// <summary>
		/// Adds the range of items to collection.
		/// </summary>
		/// <typeparam name="TItem">The type of the item.</typeparam>
		/// <param name="collection">The collection.</param>
		/// <param name="items">The items.</param>
		/// <exception cref="System.NotSupportedException"></exception>
		public static void AddRange<TItem>(this ICollection<TItem> collection, IEnumerable<TItem> items)
		{
			items.ForEach(collection.Add);
		}

		/// <summary>
		/// Removes the range of items from collection.
		/// </summary>
		/// <typeparam name="TItem">The type of the item.</typeparam>
		/// <param name="collection">The collection.</param>
		/// <param name="items">The items.</param>
		/// <returns>The number of items removed</returns>
		/// <exception cref="ArgumentNullException"><c>collection</c> or <c>items</c> is null.</exception>
		public static int RemoveAll<TItem>(this ICollection<TItem> collection, IEnumerable<TItem> items)
		{
			if (collection == null) {
				throw new ArgumentNullException("collection");
			}
			if (items == null) {
				throw new ArgumentNullException("items");
			}
			return items.Count(collection.Remove);
		}
	}
}